package datastructure.array;

/**
 *
 * @author Lei
 */
public class FindLongestContinuousIncreasingSequence {

    public static int findLongestContinuousIncreasingSequence(int A[]) {
        int maxStartIndex = 0;
        int startIndex = 0;
        int maxLength = 1;
        int maxLengthEndWithI = 1;
        for (int i = 1; i < A.length; i++) {
            if (A[i] > A[i - 1]) {
                maxLengthEndWithI++;
                if (maxLengthEndWithI > maxLength) {
                    maxLength = maxLengthEndWithI;
                    maxStartIndex = startIndex;
                }
            }
            else {
                startIndex = i;
            }
        }

        // print out continuous sequence
        for (int j = maxStartIndex; j < maxStartIndex + maxLength - 1; j++) {
            System.out.println(A[j]);
        }

        return maxLength;

    }

    public static void main(String args[]) {
        int[] anArray = {
            -1,
            -2,
            3,
            4,
            5,
            -6
        };

        int length = FindLongestContinuousIncreasingSequence.findLongestContinuousIncreasingSequence(anArray);

        System.out.println("the longest length is : " + length);

    }
}
